#include "MCUList.h"


MCUList::MCUList()
{
    /*初始化*/
    u_list = new QList<MCUObj*>();
    u_nameList = new QStringList();

    /*创建mcuobj区域*/
    MCUObj* obj1 = new MCUObj("N32H787XIB7");
    MCUObj* obj2 = new MCUObj("STM32F104");

    list()->append(obj1);
    list()->append(obj2);

    nameList()->append(obj1->u_name);
    nameList()->append(obj2->u_name);
}

MCUList::~MCUList()
{
    delete u_nameList;
    u_nameList = nullptr;
    qDebug() << "MCUList::~MCUList()";
    for (MCUObj* item : *u_list) {
        delete item;
        item = nullptr;
    }
    delete u_list;
    u_list = nullptr;

}

QList<MCUObj*>* MCUList::list()
{
    return u_list;
}

QStringList* MCUList::nameList()
{
    return u_nameList;
}

MCUObj* MCUList::currentMCUObj(QString value)
{
    for (MCUObj* obj : *u_list) {
        if (obj->name() == value) {
            qDebug() << "找到了MCUObj" << obj;
            return obj; // 找到匹配的对象，返回指针
        }
    }
    qDebug() << "找不到该MCUObj";
    return nullptr; // 没有找到，返回nullptr
}
